/*
 * @Author: zxc
 * @Date: 2020-11-19 13:04:56
 * @LastEditTime: 2020-11-19 14:11:13
 * @LastEditors: zxc
 * @Description:装饰者模式
 */

/**
 * @Author: zxc
 * @Date: 2020-11-19 13:05:35
 * @func 飞机大战小demo
 */
// class Plane {
//   constructor(plane) {
//     this.plane = plane
//   }
//   fire() {
//     console.log("普通子弹，发射")
//   }
// }
// class MissileDecorator {
//   constructor(plane) {
//     this.plane = plane
//   }
//   fire() {
//     this.plane.fire()
//     console.log("导弹，发射")
//   }
// }
// class AtomDecorator {
//   constructor(plane) {
//     this.plane = plane
//   }
//   fire() {
//     this.plane.fire()
//     console.log("原子弹s，发射")
//   }
// }
// let plane = new Plane()
// plane = new MissileDecorator(plane)
// plane = new AtomDecorator(plane)
// plane.fire()

/**
 * @Author: zxc
 * @Date: 2020-11-19 13:28:57
 * @func AOP装饰函数
 */
Function.prototype.before = function (beforeFn) {
  var _self = this
  return function (...args) {
    if (beforeFn.apply(this, args) === false) {
      return
    }
    return _self.apply(this, args)
  }
}
Function.prototype.after = function (afterFn) {
  let _self = this
  return function (...args) {
    let ret = _self.apply(this, args)
    afterFn.apply(this, args)
    return ret
  }
}
